package com.graduation.check.controller;

import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/test")
public class TestController {

    @GetMapping("/hello")
    public Map<String, String> hello() {
        Map<String, String> response = new HashMap<>();
        response.put("message", "Hello World! GET 方法正常工作");
        response.put("timestamp", String.valueOf(System.currentTimeMillis()));
        return response;
    }

    // 添加一个简单的POST接口
    @PostMapping("/hello-post")
    public Map<String, Object> helloPost(@RequestBody Map<String, String> request) {
        Map<String, Object> response = new HashMap<>();
        response.put("message", "POST 方法正常工作");
        response.put("received_data", request);
        response.put("timestamp", System.currentTimeMillis());
        return response;
    }

    // 添加一个简单的登录接口（不依赖数据库）
    @PostMapping("/simple-login")
    public Map<String, Object> simpleLogin(@RequestBody Map<String, String> loginRequest) {
        Map<String, Object> response = new HashMap<>();

        String account = loginRequest.get("account");
        String password = loginRequest.get("password");

        // 简单模拟登录验证
        if ("admin".equals(account) && "admin123".equals(password)) {
            response.put("code", 200);
            response.put("message", "简单登录成功");
            response.put("token", "simple-test-token");
        } else {
            response.put("code", 401);
            response.put("message", "账号或密码错误");
        }

        return response;
    }

    @GetMapping("/check-paths")
    public Map<String, String> checkPaths() {
        Map<String, String> paths = new HashMap<>();
        paths.put("健康检查", "GET /api/health");
        paths.put("测试接口", "GET /api/test/hello");
        paths.put("登录接口", "POST /api/auth/login");
        return paths;
    }
}